/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.SQLException;
import pojo.*;

/**
 *
 * @author Thanh Minh
 */
public class BenhDAO {
    public static int themLoaiBenh(Benh B){     
        int n=-1;
        try{
        MysqldataAccesshelper helper = new MysqldataAccesshelper();
        helper.open();
         String sql=String.format("INSERT INTO benh (MaBenh,TenBenh) VALUES (%d,'%s')",B.getMaBenh(),B.getTenBenh() );
         n = helper.executeUpdate(sql);        
        helper.close();
        }
        catch(SQLException ex){
            System.out.println("Them that bai"+ ex.getMessage());
        }  
         return n;
    }
    public static int chinhSuaLoaiBenh(int MaBenh,String TenBenh){     
        int n=-1;
        try{
        MysqldataAccesshelper helper = new MysqldataAccesshelper();
        helper.open();
         String sql=String.format("Update  benh set TenBenh='%s' where MaBenh=%d ",TenBenh,MaBenh );
         n = helper.executeUpdate(sql);        
        helper.close();
        }
        catch(SQLException ex){
            System.out.println("Cap nhat that bai"+ ex.getMessage());
        }  
         return n;
    }
    public static int xoaBenhNhan(int MaBenh){
     int n=-1;
     try{
          MysqldataAccesshelper helper = new MysqldataAccesshelper();
          helper.open();
         String sql=String.format(" DELETE FROM benh WHERE MaBN=%d",MaBenh);
         n = helper.executeUpdate(sql);        
        helper.close();
     }
     catch(SQLException e )
     {
         System.out.println("khong xoa duoc "+e.getMessage());
     }
     return n;
 }
}
